#include "mainwindowD1_01.h"
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QStackedWidget>
#include <QLabel>

MainWindow::MainWindow(QWidget *parent) : QWidget(parent) {
    setupLayout();
}

void MainWindow::setupLayout() {
    // 主水平布局
    QHBoxLayout *mainLayout = new QHBoxLayout(this);

    // 左侧按钮布局
    QVBoxLayout *buttonLayout = new QVBoxLayout();
    QPushButton *btnPage1 = new QPushButton("页面1");
    QPushButton *btnPage2 = new QPushButton("页面2");
    QPushButton *btnPage3 = new QPushButton("页面3");

    buttonLayout->addWidget(btnPage1);
    buttonLayout->addWidget(btnPage2);
    buttonLayout->addWidget(btnPage3);
    buttonLayout->addStretch();

    // 右侧堆叠窗口
    QStackedWidget *stackedWidget = new QStackedWidget();
    QLabel *page1 = new QLabel("这是页面 1");
    QLabel *page2 = new QLabel("这是页面 2");
    QLabel *page3 = new QLabel("这是页面 3");

    stackedWidget->addWidget(page1);
    stackedWidget->addWidget(page2);
    stackedWidget->addWidget(page3);

    // 添加到主布局
    mainLayout->addLayout(buttonLayout);
    mainLayout->addWidget(stackedWidget, 1);

    // 按钮切换页面
    connect(btnPage1, &QPushButton::clicked, [=]() {
        stackedWidget->setCurrentIndex(0);
    });
    connect(btnPage2, &QPushButton::clicked, [=]() {
        stackedWidget->setCurrentIndex(1);
    });
    connect(btnPage3, &QPushButton::clicked, [=]() {
        stackedWidget->setCurrentIndex(2);
    });
}
